package com.yunfei.api.v2.contants;

import com.yunfei.api.v2.enums.ContractTemplateDataEnum;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: 合同模板关键字替换
 * @author: zhengyunfei
 * @create: 2019-07-29 17:15
 **/
public class TemplateReplaceKeyValueList {
  private String key;
  private String value;

    public TemplateReplaceKeyValueList(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
    /**
    * @Description: 将json数据替换为模板需要的json数据
    * @Author: zhengyunfei
    * @Date: 2019/8/14
    * @time:11:23
    */
    public static StringBuffer replace(String json){
        List<TemplateReplaceKeyValueList> list=new ArrayList<>();
        //如果key有部分重复对的，则先加长度比较长的
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.buyAmtUpper.getCode(),ContractTemplateDataEnum.buyAmtUpper.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.custName.getCode(),ContractTemplateDataEnum.custName.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.custIdenNo.getCode(),ContractTemplateDataEnum.custIdenNo.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.mobileNo.getCode(),ContractTemplateDataEnum.mobileNo.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.buyAmt.getCode(),ContractTemplateDataEnum.buyAmt.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.bankNm.getCode(),ContractTemplateDataEnum.bankNm.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.bankBrunNm1.getCode(),ContractTemplateDataEnum.bankBrunNm1.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.bankBrunNm2.getCode(),ContractTemplateDataEnum.bankBrunNm2.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.acctNo.getCode(),ContractTemplateDataEnum.acctNo.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.prodNm.getCode(),ContractTemplateDataEnum.prodNm.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.contNo.getCode(),ContractTemplateDataEnum.contNo.getMessage()));
        //list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.maxScale.getCode(),ContractTemplateDataEnum.maxScale.getMessage()));
       // list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.undsUse.getCode(),ContractTemplateDataEnum.undsUse.getMessage()));
       // list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.riskControl.getCode(),ContractTemplateDataEnum.riskControl.getMessage()));
       // list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.repaySource.getCode(),ContractTemplateDataEnum.repaySource.getMessage()));
       // list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.filing.getCode(),ContractTemplateDataEnum.filing.getMessage()));
        //list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.intDesc.getCode(),ContractTemplateDataEnum.intDesc.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.custAdd.getCode(),ContractTemplateDataEnum.custAdd.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.intRate.getCode(),ContractTemplateDataEnum.intRate.getMessage()));
        //list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.downContNo.getCode(),ContractTemplateDataEnum.downContNo.getMessage()));
       // list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.prodTerm.getCode(),ContractTemplateDataEnum.prodTerm.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.column1.getCode(),ContractTemplateDataEnum.column1.getMessage()));
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.column2.getCode(),ContractTemplateDataEnum.column2.getMessage()));
        //客户名称
        list.add(new TemplateReplaceKeyValueList(ContractTemplateDataEnum.custNmSpci.getCode(),ContractTemplateDataEnum.custNmSpci.getMessage()));
        for(int i=0;i<list.size();i++){
            String key=list.get(i).getKey();
            String value=list.get(i).getValue();
            if(json.contains(key)){
                json=json.replace(key,value);
            }
        }
        StringBuffer stringBuffer= new StringBuffer();
        stringBuffer.append(json.replace("",""));
        return stringBuffer;
    }
}
